//
//  NSObject+Tools.m
//  YunGou
//
//  Created by macbook on 16/5/17.
//  Copyright © 2016年 macbook. All rights reserved.
//

#import "NSObject+Tools.h"
#import <objc/message.h>

@implementation NSObject (Tools)
//字典转模型
+ (instancetype)modelWithDict:(NSDictionary *)dict{
    return [[self alloc] initWithDict:dict];
}

- (instancetype)initWithDict:(NSDictionary *)dict{
    if (self = [self init]) {
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
}

static id accessoryObject;
/**设置一个辅助对象*/
- (void)setAccessoryObject:(id)object{
    objc_setAssociatedObject(self, &accessoryObject, object, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
/**得到辅助对象*/
- (id)getAccessoryObject{
    return objc_getAssociatedObject(self, &accessoryObject);
}

//类文件初始化
+(id)classInitializtion{
    return [[self alloc]init];
}

//xib初始化
+(id)nibInitializtion{
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil]lastObject];
}


@end
